package com.example.shop

import com.example.base.mvi.BaseViewModel
import com.example.base.mvi.HttpType
import com.example.base.net.ApiService
import com.example.base.net.ShopApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
@HiltViewModel
class ShopViewModel @Inject constructor(val shopApiService: ShopApiService):BaseViewModel<ShopIntent>() {
    override fun handleIntent(it: ShopIntent) {
        when(it){
            is ShopIntent.product -> {
                pageRequest({ProductDataSource(shopApiService)})
            }

            is ShopIntent.cart -> httpRequest(shopApiService.cart(it.isVaild,it.limit,it.page))
            is ShopIntent.cartDelete -> httpRequest(shopApiService.cartDelete(it.ids),HttpType.DELETE)
            is ShopIntent.cartUpdate -> httpRequest(shopApiService.cartUpdate(it.id,it.number),HttpType.UPDATE)
            is ShopIntent.orderCreate -> httpRequest(shopApiService.orderCreate(toBody(it.orderCreate)),HttpType.ADD)
        }
    }

}